﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace KeyboardController
{
    /// <summary>
    /// Interaction logic for VisualOutput.xaml
    /// </summary>
    public partial class VisualOutput : UserControl
    {
        private const int LineBufferSize = 5;

        public VisualOutput()
        {
            InitializeComponent();
        }

        public void ChangeText(string newText)
        {
            this.tb_TextOutput.Text = newText + Environment.NewLine;
        }

        public void AppendTextLine(string newLine)
        {
            var entries = this.tb_TextOutput.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            if (entries.Length >= LineBufferSize)
            {
                this.tb_TextOutput.Text = string.Empty;
                foreach (var entry in entries.Reverse().Take(LineBufferSize - 1).Reverse())
                {
                    this.tb_TextOutput.Text += entry + Environment.NewLine;
                }
            }

            this.tb_TextOutput.Text += newLine + Environment.NewLine;
        }
    }
}
